package demo.batch;

import demo.StudentMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import pojo.FullStudent;
import pojo.Student;

import java.io.IOException;
import java.io.Reader;
import java.util.Date;
import java.util.List;

/**
 * @Author ISJINHAO
 * @Date 2020/11/26 19:52
 */
public class BatchInsert {

    public static void main(String[] args) {

        String resource = "mybatis-config.xml";
        Reader reader;
        try {
            reader = Resources.getResourceAsReader(resource);
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
            SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);

            StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
//            mapper.insert()

            try {
                StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);
                Student student = new Student("123", "小红", "男", new Date(), "95034");
//                studentMapper.insert(student);
                List<FullStudent> fullStudents = studentMapper.selectFullStudent(null);
                fullStudents.forEach(System.out::println);
            } finally {
                sqlSession.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
